package com.exam.controller;

import com.exam.entity.*;
import com.exam.serviceimpl.LoginServiceImpl;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class LoginController {
    @Autowired
    private LoginServiceImpl loginService;
    @PostMapping("/login")
    public ApiResult login(@RequestBody Login login) {
        System.out.println(login.getUsername());
        System.out.println(login.getPassword());
        //管理员账号
        Admin adminRes = loginService.adminLogin(login);
        if (adminRes != null) {
            return ApiResultHandler.buildApiResult(200, "请求成功", adminRes);
        }
        //老师账号
        Teacher teacherRes = loginService.teacherLogin(login);
        if (teacherRes != null) {
            return ApiResultHandler.buildApiResult(200, "请求成功", teacherRes);
        }
        //学生账号
        Student studentRes = loginService.studentLogin(login);
        if (studentRes != null) {
            return ApiResultHandler.buildApiResult(200, "请求成功", studentRes);
        }
        return ApiResultHandler.buildApiResult(400, "请求失败", null);
    }
}
